package core

import (
	"sync"
)

// ErrorLogCallback 定义错误日志回调函数类型
type ErrorLogCallback func(message string)

var (
	errorLogCallback ErrorLogCallback
	callbackMutex    sync.RWMutex
)

// SetErrorLogCallback 设置错误日志回调
func SetErrorLogCallback(callback ErrorLogCallback) {
	callbackMutex.Lock()
	defer callbackMutex.Unlock()
	errorLogCallback = callback
}

// GetErrorLogCallback 获取错误日志回调
func GetErrorLogCallback() ErrorLogCallback {
	callbackMutex.RLock()
	defer callbackMutex.RUnlock()
	return errorLogCallback
}

// LogError 记录错误日志
func LogError(message string) {
	if cb := GetErrorLogCallback(); cb != nil {
		cb(message)
	}
}
